package com.cssy.xxkj.attach.util;

import java.util.List;
import java.util.Map;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import net.sf.json.util.CycleDetectionStrategy;

public final class JsonUtils {

	public static final String toJson(final Object src, final String[] excludePropertity) {
		JsonConfig jsonConfig = new JsonConfig();
		jsonConfig.setExcludes(excludePropertity);
		jsonConfig.setIgnoreDefaultExcludes(false);
		jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
		return JSONObject.fromObject(src, jsonConfig).toString();
	}

	public static final JSONArray toJsonArray(final List<Map<String, Object>> src, final String[] excludePropertity) {
		JsonConfig jsonConfig = new JsonConfig();
		jsonConfig.setExcludes(excludePropertity);
		jsonConfig.setIgnoreDefaultExcludes(false);
		jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
		JSONArray array = new JSONArray();
		for (Map<String, Object> ele : src) {
			array.element(ele);
		}
		return JSONArray.fromObject(src, jsonConfig);
	}
}
